using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace DataAccessLayer
{
    public class DAO_Course
    {
        public static bool Insert(Object tmp)
        {
            COURSE obj = (COURSE)tmp;
            bool result = false;
            List<SqlParameter> _list = new List<SqlParameter>();
            _list.Add(new SqlParameter("@COURSE_CREDIT", obj.COURSE_CREDIT));
            _list.Add(new SqlParameter("@COURSE_ID", obj.COURSE_ID));
            _list.Add(new SqlParameter("@COURSE_NAME", obj.COURSE_NAME));

            int n = clsDataAccessHelper.ExecNonQuery("sp_course_insert", _list);
            if (n == 1)
                result = true;
            return result;
        }

        public static bool Update(Object tmp)
        {
            COURSE obj = (COURSE)tmp;
            bool result = false;
            List<SqlParameter> _list = new List<SqlParameter>();
            _list.Add(new SqlParameter("@COURSE_CREDIT", obj.COURSE_CREDIT));
            _list.Add(new SqlParameter("@COURSE_ID", obj.COURSE_ID));
            _list.Add(new SqlParameter("@COURSE_NAME", obj.COURSE_NAME));

            int n = clsDataAccessHelper.ExecNonQuery("sp_course_update", _list);
            if (n == 1)
                result = true;
            return result;
        }

        public static bool Delete(Object tmp)
        {
            COURSE obj = (COURSE)tmp;
            bool result = false;
            List<SqlParameter> _list = new List<SqlParameter>();
            //_list.Add(new SqlParameter("@COURSE_CREDIT", obj.COURSE_CREDIT));
            _list.Add(new SqlParameter("@COURSE_ID", obj.COURSE_ID));
            //_list.Add(new SqlParameter("@COURSE_NAME", obj.COURSE_NAME));

            int n = clsDataAccessHelper.ExecNonQuery("sp_course_delete", _list);
            if (n == 1)
                result = true;
            return result;
        }

        public static DataTable LoadAll()
        {
            return clsDataAccessHelper.ExecuteQuery("sp_course_get_all", null);
        }

        public static DataTable Get(string courseID)
        {
            List<SqlParameter> _list = new List<SqlParameter>();
            _list.Add(new SqlParameter("@COURSE_ID", courseID));
            return clsDataAccessHelper.ExecuteQuery("sp_course_get", _list);
        }
    }
}
